import { contextBridge, ipcRenderer } from 'electron'

// window 里注入全局变量
contextBridge.exposeInMainWorld('electron', {
  nodeVersion: process.versions.node,
  electronVersion: process.versions.electron,
})

// https://www.electronjs.org/zh/docs/latest/tutorial/ipc
contextBridge.exposeInMainWorld('ipcRenderer', {
  getFilePath: () => ipcRenderer.invoke('getFilePath'),
  getInstallPath: () => ipcRenderer.invoke('getInstallPath'),
  download: (url: string) => ipcRenderer.invoke("download", url),
  onMessage (fn: (message: string) => void) {
    ipcRenderer.on('message', (e, message) => fn(message))
  },
})
